package models;

import java.security.SecureRandom;

import models.msgs.Card;

public class Deck2 {

    private static String[] suits = {"hearts", "spades", "diamonds", "clubs"};//serce,wino,romb,trefl
    private static String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen","King"}; 
    
    static String giveFullName(int nr) {
	return (ranks[nr%13]+" of "+ suits[nr%4]);
    }
    
    public static final int DECK_SIZE = 52;
    public static int CARD_IN_DECK = 0;
    public static int CARD_RETURNED = -1;
    private int[] deck;
    private int cardLeft;
    SecureRandom Generator;

    /**
     * Deck2 is
     */
    public Deck2() {
	this.deck = new int[DECK_SIZE];
	this.cardLeft = DECK_SIZE;
	this.Generator = new SecureRandom();
    }

    /**
     * unused
     */
    public void printDeck2() {
	for (int i = 0; i < 4; i++) {
	    for (int j = 0; j < 13; j++) {
		System.out.print(deck[i * 13 + j] + " ");
	    }
	    System.out.print("\n");
	}
    }

    public void shuffle() {
	for (int i = 0; i < DECK_SIZE; i++) {
	    if (deck[i] == CARD_RETURNED) {
		deck[i] = CARD_IN_DECK;
		cardLeft++;
	    }
	}
    }

    public int giveCard(int player) {
	// System.out.println(cardLeft);
	if (cardLeft == 0)
	    shuffle();
	int candidate = Generator.nextInt(DECK_SIZE);
	while (deck[candidate] != 0) {
	    candidate = Generator.nextInt(DECK_SIZE);
	}
	deck[candidate] = player;
	cardLeft--;
	return candidate;
    }

    public void returnCardToDeck2(int card) {
	deck[card] = CARD_RETURNED;
    }

    public int getOwnerNumber(int card) {
	return deck[card];
    }

}